﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sahit.iSoilHotel.Portal.ServiceProxy.Common;
using Sahit.iSoilHotel.Portal.ServiceProxy.Tavern;
using Sahit.iSoilHotel.Portal.ServiceProxy.Tavern.Proxys.Authentication;
using Sahit.iSoilHotel.Portal.ServiceProxy.Tavern.Models.Account;

namespace Sahit.iSoilHotel.Portal.Controllers
{
    public class AccountController : Controller
    {
        private HttpContextBase httpContext;
        private ITavernAuthenticationServiceProxy tavernServiceProxy;

        public AccountController(
            HttpContextBase httpContext,
            ITavernAuthenticationServiceProxy tavernServiceProxy)
        {
            this.httpContext = httpContext;
            this.tavernServiceProxy = tavernServiceProxy;
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult LogOn()
        {
            return View();
        }

        public ActionResult LogOff()
        {
            tavernServiceProxy.SignOut();
            return RedirectToAction("LogOn");
        }

        [HttpPost]
        public ActionResult LogOn(AccountLogOnModel model)
        {
            string userName = model.UserName;
            string password = model.Password;
            if (tavernServiceProxy.ValidateAccount(userName, password))
            {
                tavernServiceProxy.SignIn(userName);
            }
            return RedirectToAction("Index", "Home");
        }
    }
}
